var express = require('express');
var router = express.Router();
const schedulesApi = require('../api/schedules')
/* GET home page. */

/**
 * @swagger
 * /schedules/gettheaters:
 *    get:
 *      tags:
 *      - 排片模块         # 接口分类
 *      summary: 通过影院_id获取不同影院下的放映厅   # 接口备注
 *      description: 通过影院_id获取不同影院下的放映厅   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      parameters:
 *        - in: query
 *          name: cinemasId
 *          schema:
 *            type: string
 *            default: 60ddae2613abde4cf4a6735f
 *          description: 影院_id
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "电影数据获取成功！！！" # 返回 电影数据
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/theaters'
 * */

// 通过影院_id获取该影院下的放映厅
router.get('/gettheaters', async function (req, res, next) {
    const { cinemasId } = req.query
    console.log('cinemasId', cinemasId);
    const data = await schedulesApi.gettheaters(cinemasId)
    res.send(data)
});

/**,
 * @swagger
 * /schedules/examine/{_id}:
 *    get:
 *      tags:
 *      - 排片模块           # 接口分类
 *      summary: 通过电影_id 查看该电影的排片情况   # 接口备注
 *      description: 通过电影_id 查看该电影的排片情况  # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      parameters:
 *        - in: path
 *          name: _id
 *          schema:
 *            type: string
 *            default: 60d9ef30fa1cc14e44722e95
 *          required: true
 *          description: 电影 _id
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "返回在排片集合中关联的电影、影院、放映厅的数据"     # 返回 code 码描述
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/dele'
 * */
//  ---------------->
router.get('/examine/:_id', async function (req, res, next) {
    const { _id } = req.params
    const data = await schedulesApi.getMociesFormschedules(_id)
    res.send(data)
});

/**
 * @swagger
 * /schedules/getSchedules:
 *    get:
 *      tags:
 *      - 排片模块         # 接口分类
 *      summary: 获取影院数据   # 接口备注
 *      description: 获取影院数据   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "影院数据获取成功！！！" # 返回 影院数据
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/cinemas'
 * */

// 获取影院数据
router.get('/getSchedules', async function (req, res, next) {
    const data = await schedulesApi.getAll()
    res.send(data)
});

/**
 * @swagger
 * /schedules/deletePaipian:
 *    delete:
 *      tags:
 *      - 排片模块         # 接口分类
 *      summary: 删除排片接口   # 接口备注
 *      description: 通过排片生成的_id删除该排片 返回删除排片后余下该电影的排片集合   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      requestBody:
 *        required: true
 *        content:
 *          application/json:
 *            schema:
 *              $ref: '#/components/schemas/deleteschediles'
 *            example:
 *              _id: "60ded5115fe9e412f450a428"
 *              movies_id: "60deae9684ef963df87c91a7"
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "排片删除成功,返回该电影的其他排片情况" # 返回 影院数据
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/dele'
 * */

// 删除排片
router.delete('/deletePaipian', async function (req, res, next) {
    const { _id, movies_id } = req.body
    await schedulesApi.deletePaipian(_id)
    const data = await schedulesApi.getMociesFormschedules(movies_id)
    res.send(data)
});


/**
 * @swagger
 * /schedules/addData:
 *    post:
 *      tags:
 *      - 排片模块         # 接口分类
 *      summary: 新增排片接口   # 接口备注
 *      description: 新增排片接口   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      requestBody:
 *        required: true
 *        content:
 *          application/json:
 *            schema:
 *              $ref: '#/components/schemas/schedules'
 *            example:
 *              theaterId: "60debbb7217ffc4d506ec8c6"
 *              movieId: "60deae9684ef963df87c91a7"
 *              cinemasId: "60ddae2613abde4cf4a6735f"
 *              price: "15元"
 *              showTime: "14:31"
 *              date: "2021-07-22"
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "排片新增成功,返回true" # 返回 true
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/schedules'
 * */

// 新增排片
router.post('/addData', async function (req, res, next) {
    const aa = req.body
    await schedulesApi.creatSchedule(aa)
    res.send(true)
});

/**,
 * @swagger
 * /schedules/xiuGaiPaiPian:
 *    patch:
 *      tags:
 *      - 排片模块          # 接口分类
 *      summary: 修改排片接口   # 接口备注
 *      description: 修改排片接口   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      requestBody:
 *        required: true
 *        content:
 *          application/json:
 *            schema:
 *              $ref: '#/components/schemas/updataSched'
 *            example:
 *              _id: "60e024824bca5c1460b2a3bf"
 *              theaterId: "60debbb7217ffc4d506ec8c6"
 *              movies_id: "60deae9684ef963df87c91a7"
 *              price: "15元"
 *              showTime: "14:31"
 *              date: "2021-07-22"
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "删除成功后返回该电影在排片集合下修改后的数据"     # 返回 修改成功后的数据
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/dele'
 * */

// 修改排片
router.patch('/xiuGaiPaiPian', async function (req, res, next) {
    const { _id, theaterId, price, showTime, date, movies_id } = req.body
    await schedulesApi.xiuGaiPaiPian({ _id, theaterId, price, showTime, date })
    const data = await schedulesApi.getMociesFormschedules(movies_id)
    res.send(data)
});

/**
 * @swagger
 * /schedules/getmovies:
 *    get:
 *      tags:
 *      - 排片模块         # 接口分类
 *      summary: 获取电影数据接口   # 接口备注
 *      description: 获取电影数据接口   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      parameters:
 *        - in: query
 *          name: curpage
 *          schema:
 *            type: string
 *            default: 1
 *          description: 当前页
 *        - in: query
 *          name: eachpage
 *          schema:
 *            type: string
 *            default: 5
 *          description: 每页显示条数
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "电影数据获取成功,返回电影信息数据" # 返回 电影数据
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/movies'
 * */

// 获取电影数据
router.get('/getmovies', async function (req, res, next) {
    const { curpage, eachpage } = req.query
    const data = await schedulesApi.getmovies({ curpage, eachpage })
    res.send(data)
});


router.get('/schedulesOne/:_id', async function (req, res, next) {
    const { _id } = req.params
    const data = await schedulesApi.schedulesOne(_id)
    res.send(data)
});


module.exports = router;

